﻿using System;
using System.Collections.Generic;
using Ext.Net;
using BLL;
using Model;
using System.Xml;
using System.Xml.Xsl;

namespace Web.View.t404Menu
{
    public partial class Default : UIPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        //绑定Grid
        protected void t404_DataBind(object sender, StoreRefreshDataEventArgs e)
        {
            t404Mgr mgr = new t404Mgr();
            e.Total = int.Parse(mgr.GetRecordCount_t404(e.Parameters[t404_Filter.ParamPrefix]));
            IList<t404> list = mgr.FindAllByPage_t404(e.Start.ToString(), e.Limit.ToString(), e.Parameters[t404_Filter.ParamPrefix]);
            t404_MainStore.DataSource = list;
            t404_MainStore.DataBind();
        }
        //删除数据
        protected void BtnDel_Click(object sender, DirectEventArgs e)
        {
            t404Mgr mgr = new t404Mgr();
            RowSelectionModel sm = t404_Grid.SelectionModel.Primary as RowSelectionModel;
            foreach (SelectedRow row in sm.SelectedRows)
            {
                t404 _t404 = new t404();
                _t404.t404_00 = row.RecordID;//int.Parse(row.RecordID);
                if (mgr.Del_t404(_t404))
                {
                    log.Debug("t404中执行了删除，并成功");
                    X.Msg.Notify("成功", "<font color='green'>已经成功删除选中的记录</font>").Show();
                }
                else
                    X.Msg.Notify("失败", "<font color='green'>删除记录失败，请您重试！</font>").Show();
            }
            t404_Grid.Reload();
        }
        protected void BtnSave_Click(object sender, DirectEventArgs e)
        {
            t404Mgr mgr = new t404Mgr();
            t404 _t404 = new t404();
            if (Hid.Text.Length > 0)
                _t404 = mgr.FindById_t404(int.Parse(Hid.Text));
            
			_t404.t404_01 = Txtt404_01.Text.Trim();
			_t404.t404_02 = Txtt404_02.Text.Trim();
			_t404.t404_03 = Txtt404_03.Text.Trim();
			_t404.t404_04 = Txtt404_04.Text.Trim();
			_t404.t404_05 = Txtt404_05.Text.Trim();
			_t404.t404_06 = Txtt404_06.Text.Trim();
			_t404.t404_07 = Txtt404_07.Text.Trim();
			_t404.t404_08 = Txtt404_08.Text.Trim();
			_t404.t404_09 = Txtt404_09.Text.Trim();
			_t404.t404_10 = Txtt404_10.Text.Trim();
			_t404.t404_11 = Txtt404_11.Text.Trim();
			_t404.t404_12 = Txtt404_12.Text.Trim();
			_t404.t404_13 = Txtt404_13.Text.Trim();
			_t404.t404_14 = Txtt404_14.Text.Trim();
			_t404.t404_15 = Txtt404_15.Text.Trim();
			_t404.t404_16 = Txtt404_16.Text.Trim();
			_t404.t404_17 = Txtt404_17.Text.Trim();
			_t404.t404_18 = Txtt404_18.Text.Trim();
			_t404.t404_19 = Txtt404_19.Text.Trim();
			_t404.t404_20 = Txtt404_20.Text.Trim();
			_t404.t404_21 = Txtt404_21.Text.Trim();
			_t404.t404_22 = Txtt404_22.Text.Trim();
			_t404.t404_23 = Txtt404_23.Text.Trim();
			_t404.t404_24 = Txtt404_24.Text.Trim();
			_t404.t404_25 = Txtt404_25.Text.Trim();
			_t404.t404_26 = Txtt404_26.Text.Trim();
			_t404.t404_27 = Txtt404_27.Text.Trim();
			_t404.t404_28 = Txtt404_28.Text.Trim();
			_t404.t404_29 = Txtt404_29.Text.Trim();
			_t404.t404_30 = Txtt404_30.Text.Trim();
			_t404.t404_31 = Txtt404_31.Text.Trim();
			_t404.t404_32 = Txtt404_32.Text.Trim();
			_t404.t404_33 = Txtt404_33.Text.Trim();
			_t404.t404_34 = Txtt404_34.Text.Trim();
			_t404.t404_35 = Txtt404_35.Text.Trim();
			_t404.t404_36 = Txtt404_36.Text.Trim();
			_t404.t404_37 = Txtt404_37.Text.Trim();
			_t404.t404_38 = Txtt404_38.Text.Trim();
			_t404.t404_39 = Txtt404_39.Text.Trim();
			_t404.t404_40 = Txtt404_40.Text.Trim();
			_t404.t404_41 = Txtt404_41.Text.Trim();
			_t404.t404_42 = Txtt404_42.Text.Trim();
			_t404.t404_43 = Txtt404_43.Text.Trim();
			_t404.t404_44 = Txtt404_44.Text.Trim();
			_t404.t404_45 = Txtt404_45.Text.Trim();
			_t404.t404_46 = Txtt404_46.Text.Trim();
			_t404.t404_47 = Txtt404_47.Text.Trim();
			_t404.t404_48 = Txtt404_48.Text.Trim();
			_t404.t404_49 = Txtt404_49.Text.Trim();
			_t404.t404_50 = Txtt404_50.Text.Trim();
			_t404.t404_51 = Txtt404_51.Text.Trim();
			_t404.t404_52 = Txtt404_52.Text.Trim();
			_t404.t404_53 = Txtt404_53.Text.Trim();
			_t404.t404_54 = Txtt404_54.Text.Trim();
			_t404.t404_55 = Txtt404_55.Text.Trim();
			_t404.t404_56 = Txtt404_56.Text.Trim();
			_t404.t404_57 = Txtt404_57.Text.Trim();
			_t404.t404_58 = Txtt404_58.Text.Trim();
			_t404.t404_59 = Txtt404_59.Text.Trim();
			_t404.t404_60 = Txtt404_60.Text.Trim();
			_t404.t404_61 = Txtt404_61.Text.Trim();
			_t404.t404_62 = Txtt404_62.Text.Trim();
			_t404.t404_63 = Txtt404_63.Text.Trim();
			_t404.collection_time = Txtcollection_time.Text.Trim();

            bool isok = false;
            if (Hid.Text.Length > 0)
                isok = mgr.Update_t404(_t404);
            else
                isok = mgr.Add_t404(_t404);
            if (isok)
            {
                t404_Win.Hide();
                X.Msg.Notify("成功", "<font color='green'>恭喜您，操作成功！</font>").Show();
                log.Debug("t404中执行了保存（插入或修改），并成功");
                t404_Grid.Reload();
            }
            else
                X.Msg.Notify("失败", "<font color='red'>操作失败，请您重试！</font>").Show();
        }
        //数据保存为Excel
        protected void BtnSaveToExcel(object sender, EventArgs e)
        {
            string json = ExcelGridData.Value.ToString();
            StoreSubmitDataEventArgs eSubmit = new StoreSubmitDataEventArgs(json, null);
            XmlNode xml = eSubmit.Xml;
            this.Response.Clear();
            this.Response.ContentType = "application/vnd.ms-excel";
            this.Response.AddHeader("Content-Disposition", "attachment; filename=QiDian10Excel.xls");
            XslCompiledTransform xtExcel = new XslCompiledTransform();
            xtExcel.Load(Server.MapPath("/View/ExcelTemp/Excel.xsl"));
            xtExcel.Transform(xml, null, this.Response.OutputStream);
            this.Response.End();

        }
    }
}